﻿
namespace Service
{
	using System.Linq;
	using Data.Repository;
	using System.Collections.Generic;

	public class ShippingMethodService : IShippingMethodService
	{
		private IShippingMethodRepository _shippingMethodRepository;

		#region IShippingMethodService Members

		public int CreateNewShippingMethod(Data.Entity.ShippingMethod theNewShippingMethod)
		{
			if (theNewShippingMethod == null)
			{
				return 0;
			}

			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.CreateNewShippingMethod(theNewShippingMethod);
		}

		public IList<Data.Entity.ShippingMethod> GetAllShippingMethod()
		{
			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.GetAllShippingMethod();
		}

		public IList<Data.Entity.ShippingStatus> GetAllShippingStatus()
		{
			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.GetAllShippingStatus();
		}

		public bool DeleteShippingMethod(int id)
		{
			if (id <= 0)
			{
				return false;
			}

			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.DeleteShippingMethod(id);
		}

		public int UpdateShippingMethod(Data.Entity.ShippingMethod theShippingMethod)
		{
			if (theShippingMethod == null)
			{
				return 0;
			}

			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.UpdateShippingMethod(theShippingMethod);
		}

		public IList<Data.Entity.ShippingMethod> GetShippingMethodByProduct(int productID)
		{
			if (productID <= 0)
			{
				return null;
			}

			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.GetShippingMethodByProduct(productID);
		}

		public void SaveProduct_ShippingMethod_Mapping(int productID, int shippingMethodID)
		{
			if (productID > 0 && shippingMethodID > 0)
			{
				if (_shippingMethodRepository == null)
				{
					_shippingMethodRepository = new ShippingMethodRepository();
				}

				_shippingMethodRepository.SaveProduct_ShippingMethod_Mapping(productID, shippingMethodID);
			}
		}

		public void DeleteTheProduct_ShippingMethod_Mapping(int productID, int shippingMethodID)
		{
			if (productID > 0 && shippingMethodID > 0)
			{
				if (_shippingMethodRepository == null)
				{
					_shippingMethodRepository = new ShippingMethodRepository();
				}

				_shippingMethodRepository.DeleteTheProduct_ShippingMethod_Mapping(productID, shippingMethodID);
			}
		}

		public IList<Data.Entity.ShippingByStateAndProvince> GetShippingByStateAndProvinceByProvince(int stateProvinceID)
		{
			if (stateProvinceID <= 0)
			{
				return null;
			}

			if (_shippingMethodRepository == null)
			{
				_shippingMethodRepository = new ShippingMethodRepository();
			}

			return _shippingMethodRepository.GetShippingByStateAndProvinceByProvince(stateProvinceID);
		}

		#endregion
	}
}
